public class FindPeakGrid {
    public int rowMax(int[] arr) {
        int ret = 0;
        for (int i = 0; i < arr.length; i++) {
            ret = Math.max(ret,arr[i]);
        }
        return ret;
    }
    public int[] findPeakGrid(int[][] mat) {
        int rowLeft = 0;
        int rowRight = mat.length - 1;
        while (rowLeft < rowRight) {
            int mid = rowLeft + ((rowRight - rowLeft) >> 1);
            if (rowMax(mat[mid]) > rowMax(mat[mid + 1])) {
                rowRight = mid;
            }else {
                rowLeft = mid + 1;
            }
        }
        int ans = 0;
        for (int i = 0; i < mat[rowLeft].length; i++) {
            if (mat[rowLeft][i] > mat[rowLeft][ans]) {
                ans = i;
            }
        }
        return new int[]{rowLeft, ans};
    }
}
